﻿@model NCprod.Models.UserRole
@{
    ViewBag.Title = "个人资料--资料修改";
    Layout = "~/Views/Shared/_Layout.cshtml";
}



<script type="text/javascript">
    $(function () {

        $("#btnReturn").click(function () {
            history.go(-1);
        });

        $("#btnSave").click(function () {
            if ($("#user").val() == "") {
                alert("请填写姓名");
                return;
            }
            if ($("#phone").val() == "") {
                alert("请填写手机号码");
                return;
            }
            if ($("#passwd").val() == "") {
                alert("请填写密码");
                return;
            }
            var reg = /^(\w){6,20}$/;
            if (!reg.test($('#passwd').val())) {
                alert("密码格式不正确！");
                return;
            }

            if (!confirm("您确认要保存吗？")) {
                return;
            }
            var article = GetArticle();
            $.ajax({
                type: "POST",
                contentType: "application/json;utf-8",
                url: "/Home/Save",
                data: "{json:'" + $.toJSON(article) + "'}",
                dataType: "",
                success: function (data, textStatus) {
                    if (data === "existed") {
                        alert("该用户已注册！");
                        $('#user').val('');
                        $('#phone').val('');
                        $('#passwd').val('');
                    }
                    else if (data == "success") {
                        alert("注册成功！");
                        $('#user').val('');
                        $('#phone').val('');
                        $('#passwd').val('');
                    }
                    else {
                        alert(data);
                    }
                }
                ,
                //complete: function (XMLHttpRequest, textStatus) {
                //    //HideLoading();
                //},
                error: function (statusText, responseText) {
                    //请求出错处理
                    alert(statusText.responseText);
                }
            });
        });
    });

    // 获取所有信息
    function GetArticle() {
        var article = new Object();
        article.roleid = 1;
        article.username = $("#user").val();
        article.phone = $("#phone").val();
        article.loginpwd = $("#passwd").val();
        return article;
    }

    //手机号码验证信息
    function isMobil(s) {
        var patrn = /(^0{0,1}1[3|4|5|6|7|8|9][0-9]{9}$)/;
        if (!patrn.exec(s)) {
            return false;
        }
        return true;
    }
    //校验手机号
    function checkPhone() {
        var result = "fail";
        var Mobile = $("#phone").val();
        if (Mobile != "") {
            if (isMobil(Mobile)) {
                result = "success";
            }
            else {
                $("#divphoneerror").css('display', 'block');
                result = "fail";
            }
        }
        return result;
    }
</script>



<div style="text-align: left">
    <a href="#" id="btnReturn" class="easyui-linkbutton" iconcls="icon-back" plain="true">
        返回
    </a><span style="color: #E7E7E7">&nbsp;|&nbsp;</span><a href="#" id="btnSave" class="easyui-linkbutton"
                                                            iconcls="icon-save" plain="true">保存</a>
    <br />
    <br />
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
    <tr>
        <th align="right" class="H2">
            管理员名字：
        </th>
        <td width="20%">
            <input placeholder="2-6位字符" style="width: 250px; height: 20px;" id="user" type="text" value="" />
        </td>
        <td class="status" width="40%">
            *
        </td>
    </tr>
    <tr>
        <th align="right" class="H1">
            管理员电话：
        </th>
        <td width="20%">
            <input placeholder="请输入11位电话号码" style="width: 250px; height: 20px;" id="phone" maxlength="11" type="text" value="" />
        </td>
        <td class="status" width="40%">
            *
        </td>
    </tr>
    <tr>
        <th align="right" class="H2">
            管理员密码：
        </th>
        <td width="20%">
            <input placeholder="不能小于6位" type="password" style="width: 250px; height: 20px;" id="passwd"  value="" />
        </td>
        <td class="status" width="40%">
            *
        </td>
    </tr>
</table>






